package com.example.demo3.controller;

import com.example.demo3.bean.User;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@RestController
public class ParamController {


    //    http://localhost:9999/get?name=%E5%BC%A0%E4%B8%89&id=1
    @RequestMapping("get")
    public Object get(@RequestParam String name, @RequestParam String id) {
        System.out.println(name);
        return name;
    }

    //    http://localhost:9999/map?name=zs
    @RequestMapping("map")
    public Object map(@RequestParam Map map) {
        String name = (String) map.get("name");
        return map;
    }

    //    http://localhost:9999/userparam?name=zs&email=32342@qq.com
    @RequestMapping("userparam")
    public Object userparam(User user) {

        return user;
    }


    //  @GetMapping("param1/{name}/{id}")
    @RequestMapping("param1/{name}/{id}")
    public Object param(@PathVariable String name, @PathVariable String id) {
        System.out.println(name);
        System.out.println(id);
        return name;
    }

/*
    @PostMapping("servletdemo")
    public Object servletdemo(HttpServletRequest request){
        request.getParameter("name");
        return "servlet";
    }*/

    @PostMapping("puser")
    public Object puser(@RequestBody User user) {

        return "post";
    }

}
